package com.hsxxherp.ation.common.error;

/**
 * 系统公共组件异常
 */
public class AtionErrorException extends Exception {
    /**
     * 默认是500，这里沿用HTTP状态码
     */
    private static final String DEFAULT_ERROR_CODE = "500";

    private final AtionError error;

    private AtionErrorException(String message) {
        this(AtionError.builder().errorCode(DEFAULT_ERROR_CODE).errorMessage(message).build());
    }

    public AtionErrorException(AtionErrorMsgEnum ationErrorMsgEnum,String details) {
        this(AtionError.builder().errorCode(ationErrorMsgEnum.getErrorCode()).errorMessage(ationErrorMsgEnum.getErrorMessage()).details(details).build());
    }

    public AtionErrorException(AtionError error) {
        super(error.toString());
        this.error = error;
    }

    public AtionErrorException(AtionError error, Throwable cause) {
        super(error.toString(), cause);
        this.error = error;
    }

    public AtionErrorException(Throwable cause) {
        super(cause.getMessage(), cause);
        this.error = AtionError.builder().errorCode(DEFAULT_ERROR_CODE).errorMessage(cause.getMessage()).stacktrace(cause.toString()).build();
    }

    // getter
    public AtionError getError() {
        return error;
    }
}
